Conversation
Collaborator
Author
|
Converted to draft - G2 benchmarks are incorrect (thanks copilot) |
ac0ddce to
717ae2e
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a heuristic threshold for scalar bit‐length to choose between windowed and GLV-based scalar multiplication and updates benchmarks to measure each method across scalar widths.
- Introduce
g1ScalarMulChooseandg2ScalarMulChooseper curve and branch inScalarMultiplication/ScalarMultiplicationBase. - Update generator templates to emit the branch logic for new and existing methods.
- Enhance benchmarks (template and per-curve) to loop over scalar bit widths and compare windowed, GLV, and unified
ScalarMultiplication.
Reviewed Changes
Copilot reviewed 43 out of 43 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/generator/ecc/template/tests/point.go.tmpl | Benchmark loops over scalar widths with new method and ScalarMultiplicationMethod |
| internal/generator/ecc/template/point.go.tmpl | Inject conditional template logic to choose mulGLV vs mulWindowed |
| ecc//.go (all curves) | Add g1ScalarMulChoose/g2ScalarMulChoose, branch in ScalarMultiplication and ScalarMultiplicationBase |
| ecc//_test.go (all curves) | Update benchmarks to iterate bit-lengths, import crypto/rand, and call new methods |
Comments suppressed due to low confidence (2)
internal/generator/ecc/template/tests/point.go.tmpl:803
- This code uses fmt.Sprintf but the fmt package is not imported in this template; please add "fmt" to the imports.
b.Run(fmt.Sprintf("method=window/scalarwidth=%d", i), func(b *testing.B) {
ecc/secp256k1/secp256k1.go:55
- Typo in comment: it should read
g2ScalarMulChoose(capital 'M') to match the variable name.
// g1ScalarMulChoose and g2ScalarmulChoose indicate the bitlength of the scalar
Collaborator
Author
Fixed the benchmarks (I code generated benchmarks for G1 instead of G2 in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements switching scalar multiplication to windowed method when scalars are small (according to some heuristic).
Fixes #702
g1-method-stat.txt
g2-method-stat.txt
Type of change
Please delete options that are not relevant.
How has this been tested?
Scalar multiplication consistency has already been checked before using gopter.
How has this been benchmarked?
G1
G2
Checklist:
golangci-lintdoes not output errors locally